<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="author" content="lzy">
    <title>lzy-</title>
    <style>
        html,body{
            height: 100%;
        }
        body{
            margin: 0;
        }
        main{
            width: 800px;
            height: 500px;
            margin: 0 auto;
            border: 2px solid black;
        }
        h1{
            text-align: center;
        }
        main div{
            display: inline-block;
            margin: 10px;
            width: 140px;
            height: 140px;
            float: left;
            box-sizing: border-box;
            border: 2px solid black;
            background-color: gray;
        }
        img{
            width: 150px;
            height: 150px;
            display: none;
        }
        .active{
            display: block;
        }
    </style>
</head>
<body>
    <main>
        <h1>名车车标展示-鼠标移动显示车标</h1>
        <div><strong>BMW</strong><img src="效果图/img/1.jpg" alt=""></div>
        <div><strong>Alfa Romeo</strong><img src="效果图/img/2.jpg" alt=""></div>
        <div><strong>Skoda</strong><img src="效果图/img/3.jpg" alt=""></div>
        <div><strong>Volkswagen</strong><img src="效果图/img/4.jpg" alt=""></div>
        <div><strong>Saab</strong><img src="效果图/img/5.jpg" alt=""></div>
        <div><strong>Lamborghini</strong><img src="效果图/img/6.jpg" alt=""></div>
        <div><strong>Porsche</strong><img src="效果图/img/7.jpg" alt=""></div>
        <div><strong>Peugrot</strong><img src="效果图/img/8.jpg" alt=""></div>
        <div><strong>Mercedes1</strong><img src="效果图/img/9.jpg" alt=""></div>
        <div><strong>Buick</strong><img src="效果图/img/10.jpg" alt=""></div>
    </main>
</body>
</html>
<script>
    var divs = document.querySelectorAll('div');
    var imgs = document.querySelectorAll('img');
    var strongs = document.querySelectorAll('strong');
    for(var i=0;i<divs.length;i++){
        divs[i].index=i;     
        divs[i].onmouseover = function(){
            console.log(this.index);
            strongs[this.index].style.display='none';
            for(var j=0;j<imgs.length;j++){
                imgs[this.index].className='active';
                divs[this.index].style.width='160px';
                divs[this.index].style.height='160px';
                divs[this.index].style.margin='0px';
                divs[this.index].style.zIndex='5';
                divs[this.index].style.backgroundColor='white';
            }
        }
         divs[i].onmouseout = function(){
            strongs[this.index].style.display='block';
             for(var j=0;j<imgs.length;j++){
                imgs[this.index].className='';
                divs[this.index].style.width='140px';
                divs[this.index].style.height='140px';
                divs[this.index].style.margin='10px';
                divs[this.index].style.zIndex='1';
                divs[this.index].style.backgroundColor='gray';
            }
        }
        
       
    }
</script>